//
//  FourViewController.m
//  fp
//
//  Created by xingshuai on 2020/11/9.
//

#import "FourViewController.h"

#import "RoomCollectionViewCell.h"

static NSString *identifier = @"XAHistCollectionCellID";
static NSString *headerIdentifier = @"XAHisHeadCollectionCellID";
@interface FourViewController () <UICollectionViewDelegate, UICollectionViewDataSource>

// 数据展示
@property (nonatomic, strong) UICollectionView *collection;
@property (nonatomic, strong) NSArray *list;

@end

@implementation FourViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.list = @[@"today",@"yesterday"];
    // 添加试图内容
    [self creatClassRoomViewUI];
    
}

// 初始化ui
-(void)creatClassRoomViewUI {
    [self.view addSubview:self.collection];
    [self.collection mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(15);
        make.top.equalTo(self.navView.mas_bottom);
        make.right.equalTo(self.view.mas_right).offset(-15);
        make.bottom.equalTo(self.view).offset(-5);
    }];
}

- (UICollectionView *)collection {
    if (!_collection) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.minimumLineSpacing = 41;
        flowLayout.minimumInteritemSpacing = 10;
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        flowLayout.headerReferenceSize = CGSizeMake(ScreenWidth*0.7, 78);
        
        _collection = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        [_collection registerClass:[RoomCollectionViewCell class] forCellWithReuseIdentifier:identifier];
        _collection.showsHorizontalScrollIndicator = NO;
        _collection.dataSource = self;
        _collection.delegate = self;
        _collection.backgroundColor = [UIColor whiteColor];
        _collection.contentInset = UIEdgeInsetsMake(0, 10, 0, 10);
        
        //注册一种cell--->注册头部视图
        [_collection registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerIdentifier];
    }
    return _collection;
}

#pragma mark - UICollectionViewDelegateFlowLayout
// 返回cell的尺寸大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return CGSizeMake((self.collection.frame.size.width-50)/3, (self.collection.frame.size.width-50)/3/1.15);
}

#pragma mark - deleDate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return self.list.count;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 5;
}

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    UICollectionReusableView *headView;
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        headView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:headerIdentifier forIndexPath:indexPath];
        
        UILabel * label = [headView viewWithTag:101];
        if(!label){
            label = [[UILabel alloc]initWithFrame:CGRectMake(10, 28, 100, 50)];
            label.font = [UIFont systemFontOfSize:20];
            label.tag = 101;
            [headView addSubview:label];
        }
        label.text = [self.list objectAtIndex:indexPath.section];
    }
    return headView;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    RoomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    cell.isHidenPro = NO;
    return cell;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
